import { request } from '../../request/index'
import regeneratorRuntime from '../../lib/runtime/runtime'
// pages/artical/artical.js
Page({

    /**
     * Page initial data
     */
    data: {
        userInfo: {},
        Cates: []
    },
    /**
   * Login Method
   */
  getUserProfile: function () {
    var that = this;
    wx.getUserProfile({
        desc: '用于完善用户资料',
        success: (res) => {
          if (res.errMsg == "getUserProfile:ok") {
            wx.setStorageSync('userInfo',res.userInfo)
            app.globalData.userInfo = res.userInfo
            that.setData({
              userInfo: res.userInfo,
              hasUserInfo: true,
            })
          }
        } ,fail: err => {
          wx.showToast({
            title: '授权后才能体验更多功能哦',
            icon: 'none',
            duration: 3000
          })
        },
    })
  },

    /**
     * Lifecycle function--Called when page load
     */
    onLoad: function (options) {
        console.log(options)
        let aid = options.aid
        let baseurl = '/getArtical'
        let attr = '?aid='
        let url = baseurl + attr + aid
        console.log(url)
        this.getArticalData(url)
    },

    // get aid course information data
    async getArticalData(url) {
        // 1. 使用 es7 async await 发送请求
        const res = await request({url: url});
        console.log(res.data.data)

        // 2. 赋值给 AppData
        let Cates = res.data.data
        this.setData({
            Cates
        })
    },

    /**
     * Lifecycle function--Called when page is initially rendered
     */
    onReady: function () {

    },

    /**
     * Lifecycle function--Called when page show
     */
    onShow: function () {

    },

    /**
     * Lifecycle function--Called when page hide
     */
    onHide: function () {

    },

    /**
     * Lifecycle function--Called when page unload
     */
    onUnload: function () {

    },

    /**
     * Page event handler function--Called when user drop down
     */
    onPullDownRefresh: function () {

    },

    /**
     * Called when page reach bottom
     */
    onReachBottom: function () {

    },

    /**
     * Called when user click on the top right corner to share
     */
    onShareAppMessage: function () {

    }
})